$(function () {
    var mySwiper = new Swiper('.swiper', {
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        }, loop: true, autoplay: true, pagination: {
            el: '.swiper-pagination',
        },
        autoplay: true,
    })
    var url = 'http://localhost:3000/gd/index.php?action=ajaxlistguide&ajaxID=5bee6f7b7b20e5c1476b7168/'
    $.get(url, data => {
        console.log(JSON.parse(data))
        data = JSON.parse(data)
        $('.fourth>.jinnang>ul').html(data.data.list.map(value => {
            const { cn_name, owner_country, pic, update_time, url } = value
            function timetrans(date){
                var date = new Date(date*1000);//如果date为13位不需要乘1000
                var Y = date.getFullYear() + '-';
                var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
                var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
                var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
                var m = (date.getMinutes() <10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
                var s = (date.getSeconds() <10 ? '0' + date.getSeconds() : date.getSeconds());
                return Y+M+D;
            }
            var time = timetrans(update_time)
            return `
        <li>
                        <div><a href="${url}"><img src="${pic}" alt=""></a></div>
                        <div class='text'>
                        <p>${cn_name}</p>
                        <span>${owner_country}</span>
                        <span>${time} 更新</span>
                        </div>
                    </li>
        `
        }))
    })
    //编辑推荐
    var url = 'http://localhost:3000/gd/index.php?action=ajaxhotguide&ajaxID=5bebcbee7b20e5c1476b7157'
    $.get(url, data => {
        data = JSON.parse(data)
        $('.second>ul').html(
            data.data.map(value => {
                const { cn_name, isNew, pic, url } = value
                return `
            <li>
                <img src="${pic}" alt="" >
                <span>${cn_name}</span>
                <a href="${url}">下载阅读</a>
            </li>
            `
            })
        )
    })
    var url = 'http://localhost:3000/gd/index.php?action=ajaxdownguide&ajaxID=5bee682b7b20e5c1476b7164'
    $.get(url, data => {
        // console.log(JSON.parse(data))
        data = JSON.parse(data)
        $('.center>.third>ul').html(
            data.data.map(value => {
                const { avatar, cn_name, url, time } = value
                var d1 = new Date()
                console.log(d1.getTime())
                console.log(time*1000)
                var time1 = d1.getTime()/1000 - parseInt(time)
                var min = parseInt((time1%3600)/60)
                console.log('min',min)
                return `
            <li>
                    <img src="${avatar}" alt="">
                    <div>${ min == 0 ? '刚刚':min+'分钟前'}下载了<a href="${url}">${cn_name}</a>穷游锦囊</div>
                </li>
            `
            })
        )
    })
    var url = 'http://localhost:3000/gd/qcross/home/ajax?action=common&ajaxID=5ab9bea48776329315f6d189'
    $.get(url, data => {
        // console.log(JSON.parse(data))
        // data = JSON.parse(data)

    })


})